const int MAX_BONES = 100;

uniform mat4 gWVP;
uniform mat4 gWorld;
uniform mat4 gBones[MAX_BONES];

attribute vec3  in_Position;                                             
attribute vec2  in_TexCoord;                                             
attribute vec3  in_Normal;    
attribute ivec4 in_BoneIDs;
attribute vec4  in_Weights;

varying vec2 out_TexCoord;                                                                 
varying vec3 out_Normal;                                                                   
varying vec3 out_WorldPos;     

void main()
{
	mat4 BoneTransform = gBones[in_BoneIDs[0]] * in_Weights[0];
    BoneTransform     += gBones[in_BoneIDs[1]] * in_Weights[1];
    BoneTransform     += gBones[in_BoneIDs[2]] * in_Weights[2];
    BoneTransform     += gBones[in_BoneIDs[3]] * in_Weights[3];

    vec4 PosL      = BoneTransform * vec4(in_Position, 1.0);
    gl_Position    = gWVP * PosL;
    out_TexCoord = in_TexCoord;
    vec4 NormalL   = BoneTransform * vec4(in_Normal, 0.0);
    out_Normal   = (gWorld * NormalL).xyz;
    out_WorldPos = (gWorld * PosL).xyz;   
}